<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function deepClone(obj) {
        let newObj = {};
        let key;
        for (key in obj) {
          if (Object.prototype.toString.call(obj[key]) == '[Object array]') {
            deepClone(obj[key]);
          } else if (
            Object.prototype.toString.call(obj[key]) == '[Object object]'
          ) {
            deepClone(obj[key]);
          } else {
            newObj[key] = obj[key];
          }
        }
        return newObj;
      }

      var a = {
        s: 3,
        b: [1, 2, 3],
        c: {
          ss: 4,
          bb: 5,
          cc: {
            d: 4,
          },
        },
      };

      var a1 = deepClone(a);
      console.log(a);
      console.log(a1);
    </script>
  </body>
</html>
